package com.tjn.thread;

/**
 * @author 陶镓妮
 * @version 1.0
 */
public class ThreadStop {
    public static void main(String[] args) throws InterruptedException {
        MyThread myThread = new MyThread();
        new Thread(myThread).start();
        for (int i = 0; i < 60; i++) {
            System.out.println("main线程进行中。。。" + i);
            Thread.sleep(50);
            if(i == 20){
                myThread.setSetLoop(false);
            }
        }


    }
}
class MyThread implements Runnable {
    public boolean setLoop = true;
    @Override
    public void run() {
        int count= 0;
        while(setLoop){
            System.out.println("MyThread线程运行中。。。" + (++count));
            try {
                Thread.sleep(50);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }

    }

    public void setSetLoop(boolean setLoop) {
        this.setLoop = setLoop;
    }
}